﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/AdminDefault.Master"
	AutoEventWireup="true" CodeBehind="ProductList.aspx.cs" Inherits="ITViet.Web.Admin.ProductList" %>

<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
	Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
	Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
	Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
	Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Src="~/Controls/ImageUpload.ascx" TagName="ImageUpload" TagPrefix="uc1" %>
<%@ Register Assembly="DevExpress.Web.ASPxTreeList.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
	Namespace="DevExpress.Web.ASPxTreeList" TagPrefix="dxwtl" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
	<div style="padding: 5px 0 10px 0;">
		<asp:Literal ID="Literal6" runat="server" Text="<%$Resources:Strings, Category %>"></asp:Literal>:
	</div>
	<div>
		<dxwtl:ASPxTreeList ID="tlCategory" ClientInstanceName="tlCategory" runat="server"
			AutoGenerateColumns="False" KeyFieldName="Id" ParentFieldName="ParentId" Width="100%">
			<SettingsBehavior AllowDragDrop="False" AllowSort="False" AllowFocusedNode="True"
				FocusNodeOnExpandButtonClick="False" FocusNodeOnLoad="False" />
			<ClientSideEvents FocusedNodeChanged="function(s, e) {
	tlCategory_FocusedNodeChanged(s, e);
}" />
			<SettingsEditing Mode="EditFormAndDisplayNode" />
			<SettingsPager>
				<AllButton>
					<Image Height="19px" Width="28px" />
				</AllButton>
				<FirstPageButton>
					<Image Height="19px" Width="23px" />
				</FirstPageButton>
				<LastPageButton>
					<Image Height="19px" Width="23px" />
				</LastPageButton>
				<NextPageButton>
					<Image Height="19px" Width="19px" />
				</NextPageButton>
				<PrevPageButton>
					<Image Height="19px" Width="19px" />
				</PrevPageButton>
				<Summary AllPagesText="<%$Resources:Strings, PagerText %>" Text="<%$Resources:Strings, PagerText %>" />
			</SettingsPager>
			<Columns>
				<dxwtl:TreeListTextColumn Caption="<%$ Resources:Strings, Name %>" FieldName="Name"
					VisibleIndex="0">
					<HeaderStyle HorizontalAlign="Center" />
				</dxwtl:TreeListTextColumn>
			</Columns>
			<SettingsText ConfirmDelete="<%$Resources:Messages,ERR0006 %>" />
		</dxwtl:ASPxTreeList>
	</div>
	<div style="padding: 20px 0 10px 0;">
		<asp:Literal ID="Literal5" runat="server" Text="<%$Resources:Strings, Product %>"></asp:Literal>:
	</div>
	<div style="clear: both; padding: 10px 0 0">
		<dxwgv:ASPxGridView ID="gvList" runat="server" AutoGenerateColumns="False" ClientInstanceName="gvList"
			KeyFieldName="Id" Width="100%" OnCustomJSProperties="gvList_CustomJSProperties"
			OnCellEditorInitialize="gvList_CellEditorInitialize" OnHtmlEditFormCreated="gvList_HtmlEditFormCreated"
			OnStartRowEditing="gvList_StartRowEditing" OnCommandButtonInitialize="gvList_CommandButtonInitialize"
			OnCustomCallback="gvList_CustomCallback" OnPageIndexChanged="gvList_PageIndexChanged">
			<SettingsBehavior ConfirmDelete="True" AllowDragDrop="false" AllowSort="false" />
			<SettingsEditing NewItemRowPosition="Bottom" />
			<Styles>
				<Header ImageSpacing="5px" SortingImageSpacing="5px">
				</Header>
				<CommandColumnItem Cursor="pointer">
				</CommandColumnItem>
			</Styles>
			<SettingsPager>
				<AllButton>
					<Image Height="19px" Width="28px" />
				</AllButton>
				<FirstPageButton>
					<Image Height="19px" Width="23px" />
				</FirstPageButton>
				<LastPageButton>
					<Image Height="19px" Width="23px" />
				</LastPageButton>
				<NextPageButton>
					<Image Height="19px" Width="19px" />
				</NextPageButton>
				<PrevPageButton>
					<Image Height="19px" Width="19px" />
				</PrevPageButton>
				<Summary AllPagesText="<%$Resources:Strings, PagerText %>" Text="<%$Resources:Strings, PagerText %>" />
			</SettingsPager>
			<Columns>
				<dxwgv:GridViewDataImageColumn Caption="<%$ Resources:Strings, Image %>" FieldName="Image"
					VisibleIndex="0">
					<HeaderStyle HorizontalAlign="Center" />
					<PropertiesImage ImageWidth="100px">
					</PropertiesImage>
				</dxwgv:GridViewDataImageColumn>
				<dxwgv:GridViewDataTextColumn VisibleIndex="1" Caption="<%$ Resources:Strings, Name %>"
					FieldName="Name">
					<HeaderStyle HorizontalAlign="Center" />
					<CellStyle HorizontalAlign="Left">
					</CellStyle>
				</dxwgv:GridViewDataTextColumn>
				<dxwgv:GridViewDataTextColumn FieldName="Category" VisibleIndex="2" Caption="<%$ Resources:Strings, Category %>">
					<HeaderStyle HorizontalAlign="Center" />
					<CellStyle HorizontalAlign="Center">
					</CellStyle>
					<EditItemTemplate>
						<dxe:ASPxComboBox ID="cbbCategory" runat="server" TextField="Name" ValueField="Id"
							ValueType="System.Int32">
						</dxe:ASPxComboBox>
					</EditItemTemplate>
				</dxwgv:GridViewDataTextColumn>
				<dxwgv:GridViewDataTextColumn FieldName="CreatedBy" VisibleIndex="3" Caption="<%$ Resources:Strings, CreatedBy %>">
					<HeaderStyle HorizontalAlign="Center" />
					<CellStyle HorizontalAlign="Center">
					</CellStyle>
					<EditFormSettings Visible="False" />
				</dxwgv:GridViewDataTextColumn>
				<dxwgv:GridViewDataDateColumn FieldName="CreatedDate" VisibleIndex="4" Caption="<%$ Resources:Strings, CreatedDate %>"
					Width="13%">
					<HeaderStyle HorizontalAlign="Center" />
					<CellStyle HorizontalAlign="Center">
					</CellStyle>
					<EditFormSettings Visible="False" />
				</dxwgv:GridViewDataDateColumn>
				<dxwgv:GridViewDataDateColumn VisibleIndex="5" FieldName="ModifiedDate" Caption="<%$ Resources:Strings, ModifiedDate %>"
					Width="13%">
					<HeaderStyle HorizontalAlign="Center" />
					<CellStyle HorizontalAlign="Center">
					</CellStyle>
					<EditFormSettings Visible="False" />
				</dxwgv:GridViewDataDateColumn>
				<dxwgv:GridViewDataTextColumn VisibleIndex="6" Width="13%">
					<EditFormSettings Visible="False" />
					<DataItemTemplate>
						<span><a style="cursor: pointer;" onclick="ViewDetail('<%#Eval("Id") %>')">
							<asp:Label ID="Label1" runat="server" Text="<%$Resources:Strings,ViewDetail %>"></asp:Label></a>
						</span>
					</DataItemTemplate>
					<CellStyle HorizontalAlign="Center">
					</CellStyle>
				</dxwgv:GridViewDataTextColumn>
				<dxwgv:GridViewDataTextColumn VisibleIndex="7" Width="7%">
					<DataItemTemplate>
						<a id="aDelete" runat="server">
							<img alt="" src="../images/delete.png" onclick="onDelete('<%#Eval("Id")%>')" />
						</a><a id="aEdit" runat="server">
							<img alt="" src="../images/edit.png" onclick="onEdit('<%#Eval("Id")%>','<%#Eval("Name") %>','<%#Eval("CategoryId") %>','<%#Eval("Image") %>','<%#Eval("Color") %>','<%#Eval("HasInventory") %>','<%#Eval("IsHot") %>')" /></a>
					</DataItemTemplate>
					<CellStyle HorizontalAlign="Center">
					</CellStyle>
				</dxwgv:GridViewDataTextColumn>
			</Columns>
			<StylesEditors>
				<ProgressBar Height="29px">
				</ProgressBar>
			</StylesEditors>
			<ImagesEditors>
				<CalendarPrevYear Height="19px" Width="23px" />
				<CalendarPrevMonth Height="19px" Width="19px" />
				<CalendarNextMonth Height="19px" Width="19px" />
				<CalendarNextYear Height="19px" Width="23px" />
			</ImagesEditors>
			<SettingsText ConfirmDelete="<%$Resources:Messages,ERR0006 %>" />
			<ClientSideEvents EndCallback="function(s, e){gvList_EndCallback(s,e);}" />
		</dxwgv:ASPxGridView>
	</div>
	<div style="padding-top: 10px;">
		<dxe:ASPxButton ID="btnAdd" runat="server" Text="<%$ Resources:Strings, Add %>" AutoPostBack="false">
			<ClientSideEvents Click="function(s,e){onAdd();}" />
		</dxe:ASPxButton>
	</div>
	<asp:HiddenField ID="hfPid" runat="server" />
	<dxcb:ASPxCallback ID="ctrlCallback" runat="server" ClientInstanceName="ctrlCallback"
		OnCallback="ctrlCallback_Callback">
		<ClientSideEvents CallbackComplete="function(s,e){ctrlCallback_CallbackComplete(s,e);}" />
	</dxcb:ASPxCallback>
	<dxpc:ASPxPopupControl ID="pcInfo" ClientInstanceName="pcInfo" runat="server" HeaderText="<%$ Resources:Strings, Info %>"
		PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" Modal="True"
		AllowDragging="True" Width="550px">
		<ContentCollection>
			<dxpc:PopupControlContentControl>
				<div style="padding: 0 0 6px 5px;">
					<dxe:ASPxLabel ID="lblErrorMessage" ClientInstanceName="lblErrorMessage" runat="server"
						Font-Bold="true" ForeColor="Red">
					</dxe:ASPxLabel>
				</div>
				<div>
					<table>
						<tr>
							<td>
								<asp:Literal ID="Literal2" runat="server" Text="<%$Resources:Strings, Image %>"></asp:Literal>:
							</td>
							<td>
								<uc1:ImageUpload ID="imageUpload1" runat="server" />
							</td>
						</tr>
					</table>
				</div>
				<div style="float: left;">
					<table>
						<tr>
							<td>
								<asp:Literal ID="Literal4" runat="server" Text="<%$Resources:Strings, Name %>"></asp:Literal>:
							</td>
							<td>
								<dxe:ASPxTextBox ID="txtName" ClientInstanceName="txtName" runat="server" Width="200px">
								</dxe:ASPxTextBox>
							</td>
						</tr>
						<tr>
							<td>
								<asp:Literal ID="Literal3" runat="server" Text="<%$Resources:Strings, Category %>"></asp:Literal>:
							</td>
							<td>
								<dxe:ASPxComboBox ID="cbxCategory" ClientInstanceName="cbxCategory" runat="server"
									ValueType="System.Int32" Width="200px" TextField="Name" ValueField="Id">
								</dxe:ASPxComboBox>
							</td>
						</tr>
						<tr style="display: none">
							<td>
								<asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Strings, Size %>"></asp:Literal>
							</td>
							<td>
								<dxe:ASPxTextBox ID="txtSize" ClientInstanceName="txtSize" runat="server" Width="200px">
								</dxe:ASPxTextBox>
							</td>
						</tr>
						<tr>
							<td>
							</td>
							<td>
								<dxe:ASPxCheckBox ID="chbInStock" ClientInstanceName="chbInStock" runat="server"
									Text="<%$ Resources:Strings, InStock %>">
								</dxe:ASPxCheckBox>
							</td>
						</tr>
						<tr>
							<td>
							</td>
							<td>
								<dxe:ASPxCheckBox ID="chbIsHot" ClientInstanceName="chbIsHot" runat="server" Text="<%$ Resources:Strings, IsHotProduct %>">
								</dxe:ASPxCheckBox>
							</td>
						</tr>
						<tr>
							<td colspan="2" style="height: 10px;">
							</td>
						</tr>
						<tr>
							<td>
							</td>
							<td style="padding-top: 5px;">
								<div style="float: left">
									<dxe:ASPxButton ID="btnSave" runat="server" Text="<%$ Resources:Strings, Save %>"
										AutoPostBack="false">
										<ClientSideEvents Click="function(s, e){onSave();}" />
									</dxe:ASPxButton>
								</div>
								<div style="float: left; padding-left: 3px;">
									<dxe:ASPxButton ID="btnCancel" runat="server" Text="<%$ Resources:Strings, Cancel %>"
										AutoPostBack="false">
										<ClientSideEvents Click="function(s, e){closePup();}" />
									</dxe:ASPxButton>
								</div>
							</td>
						</tr>
					</table>
				</div>
				<div style="float: left; padding-left: 10px; display: none;">
					<table>
						<tr>
							<td rowspan="6">
								<asp:Literal ID="Literal8" runat="server" Text="<%$Resources:Strings, Color %>"></asp:Literal>
							</td>
						</tr>
						<tr>
							<td>
								<input class="color" value="FFF" id="ForeColor1" runat="server" style="width: 100px;
									border: 1.5px solid #C0C0C0; font-size: 13px;" />
							</td>
							<td>
								<dxe:ASPxCheckBox ID="chbColor1" ClientInstanceName="chbColor1" runat="server" Text="<%$Resources:Strings, Active %>">
								</dxe:ASPxCheckBox>
							</td>
						</tr>
						<tr>
							<td>
								<input class="color" value="FFF" id="ForeColor2" runat="server" style="width: 100px;
									border: 1.5px solid #C0C0C0; font-size: 13px;" />
							</td>
							<td>
								<dxe:ASPxCheckBox ID="chbColor2" ClientInstanceName="chbColor2" runat="server" Text="<%$Resources:Strings, Active %>">
								</dxe:ASPxCheckBox>
							</td>
						</tr>
						<tr>
							<td>
								<input class="color" value="FFF" id="ForeColor3" runat="server" style="width: 100px;
									border: 1.5px solid #C0C0C0; font-size: 13px;" />
							</td>
							<td>
								<dxe:ASPxCheckBox ID="chbColor3" ClientInstanceName="chbColor3" runat="server" Text="<%$Resources:Strings, Active %>">
								</dxe:ASPxCheckBox>
							</td>
						</tr>
						<tr>
							<td>
								<input class="color" value="FFF" id="ForeColor4" runat="server" style="width: 100px;
									border: 1.5px solid #C0C0C0; font-size: 13px;" />
							</td>
							<td>
								<dxe:ASPxCheckBox ID="chbColor4" ClientInstanceName="chbColor4" runat="server" Text="<%$Resources:Strings, Active %>">
								</dxe:ASPxCheckBox>
							</td>
						</tr>
						<tr>
							<td>
								<input class="color" value="FFF" id="ForeColor5" runat="server" style="width: 100px;
									border: 1.5px solid #C0C0C0; font-size: 13px;" />
							</td>
							<td>
								<dxe:ASPxCheckBox ID="chbColor5" ClientInstanceName="chbColor5" runat="server" Text="<%$Resources:Strings, Active %>">
								</dxe:ASPxCheckBox>
							</td>
						</tr>
					</table>
				</div>
			</dxpc:PopupControlContentControl>
		</ContentCollection>
	</dxpc:ASPxPopupControl>

	<script type="text/javascript" language="javascript">
		function gvList_EndCallback(s, e) {
			var error = gvList.cpInnerError;
			if (error != '') {
				alertMessage(error.split('|')[1]);
			}
		}
		function ViewDetail(id) {
			window.location.href = "ProductDetail.aspx?id=" + id;
		}
		function ctrlCallback_CallbackComplete(s, e) {
			pcWaiting.Hide();
			var result = e.result.split('|');
			if (result[0] == "save") {
				alert(result[1]);
			}
			else if (result[0] == "delete") {

			}
			gvList.PerformCallback();
		}
		function onAdd() {
			resetValue();
			pcInfo.Show();
		}
		function resetValue() {
			setImageName('../images/ImagePreview.png');
			txtName.SetText('');
			lblErrorMessage.SetText('');
			chbIsHot.SetValue(false);
			chbInStock.SetValue(false);
			document.getElementById('<%=hfPid.ClientID %>').value = '';
		}
		function onSave() {
			if (checkInput()) {
				pcWaiting.Show();
				ctrlCallback.PerformCallback('save|');
			}
		}
		function checkInput() {
			var error = '';
			if (txtName.GetText() == '')
				error += '<BR> + <%=GetGlobalResourceObject("Strings","Name") %>';
			if (cbxCategory.GetValue() == null)
				error += '<BR> + <%=GetGlobalResourceObject("Strings","Category") %>';
			if (error != '') {
				lblErrorMessage.SetText('<%=GetGlobalResourceObject("Messages", "ERR0008") %>' + error);
				return false;
			}
			return true;
		}
		function onEdit(id, name, catid, image, color, inStock, isHot) {
			document.getElementById('<%=hfPid.ClientID %>').value = id;
			setImageName(image);
			txtName.SetText(name);
			cbxCategory.SetValue(catid);
			chbInStock.SetValue(inStock.toLowerCase() != 'true' ? false : true);
			chbIsHot.SetValue(isHot.toLowerCase() != 'true' ? false : true);
			pcInfo.Show();
		}
		function onDelete(id) {
			if (confirm('<%=GetGlobalResourceObject("Messages", "ERR0006") %>'))
				ctrlCallback.PerformCallback('delete|' + id);
		}
		function closePup() {
			resetValue();
			pcInfo.Hide();
		}
		function tlCategory_FocusedNodeChanged(s, e) {
			var nodeKey = tlCategory.GetFocusedNodeKey();
			cbxCategory.SetValue(parseInt(nodeKey));
			gvList.PerformCallback('changeCategory|' + nodeKey);
		}
	</script>

</asp:Content>
